﻿<Page
    x:Class="Windows_8_MVVM.Pages.HomePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewModels="using:Windows_8_MVVM.ViewModels.Pages" xmlns:controls="using:Windows_8_MVVM.Controls"
    xmlns:behaviors="using:Ebt.Mvvm.Behaviors"
    mc:Ignorable="d"
    NavigationCacheMode="Enabled"
    DataContext="{Binding HomePageModel}"
    d:DataContext="{d:DesignInstance Type=viewModels:HomePageModel}">
    <UserControl.Resources>
        <Style x:Key="LandscapeStyle" TargetType="WrapGrid">
            <Setter Property="MaximumRowsOrColumns" Value="2"/>
        </Style>
        <Style x:Key="PortretStyle" TargetType="WrapGrid">
            <Setter Property="MaximumRowsOrColumns" Value="4"/>
        </Style>
    </UserControl.Resources>


    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <ContentControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
            <behaviors:OrientationBehavior.LandscapeStyle>
                <Style TargetType="ContentControl">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="120" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>

                                    <controls:LogoControl Grid.Column="1" Style="{StaticResource PageLogoStyle}"/>
                                    
                                    <ListView Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="0 30 0 0" Padding="106 0 0 0" 
                                              ItemsSource="{Binding ItemsList}"
                                              ScrollViewer.HorizontalScrollMode="Auto"
                                              ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                              ScrollViewer.VerticalScrollMode="Disabled"
                                              ScrollViewer.VerticalScrollBarVisibility="Disabled"
                                              HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                              SelectionMode="Single">
                                        <ListView.ItemTemplate>
                                            <DataTemplate>
                                                <controls:ItemControl/>
                                            </DataTemplate>
                                        </ListView.ItemTemplate>
                                        <ListView.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <WrapGrid Orientation="Vertical" 
                                                          behaviors:OrientationBehavior.LandscapeStyle="{StaticResource LandscapeStyle}"
                                                          behaviors:OrientationBehavior.PortraitStyle="{StaticResource PortretStyle}"/>
                                            </ItemsPanelTemplate>
                                        </ListView.ItemsPanel>
                                    </ListView>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </behaviors:OrientationBehavior.LandscapeStyle>
            <behaviors:OrientationBehavior.SnappedStyle>
                <Style TargetType="ContentControl">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="15" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>

                                    <StackPanel Grid.Row="0" Grid.Column="1">
                                        <controls:LogoControl Margin="45,20,0,0" Style="{StaticResource PageLogoStyle}"/>
                                    </StackPanel>
                                    <ListView Grid.Row="2" Grid.Column="1" Margin="0 20 0 0"
                                              ItemsSource="{Binding ItemsList}"
                                              ScrollViewer.HorizontalScrollMode="Disabled"
                                              ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                              ScrollViewer.VerticalScrollMode="Auto"
                                              ScrollViewer.VerticalScrollBarVisibility="Auto"
                                              HorizontalAlignment="Stretch"
                                              SelectionMode="Single">
                                        <ListView.ItemTemplate>
                                            <DataTemplate>
                                                <controls:ItemControl/>
                                            </DataTemplate>
                                        </ListView.ItemTemplate>
                                        <ListView.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <StackPanel />
                                            </ItemsPanelTemplate>
                                        </ListView.ItemsPanel>
                                    </ListView>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </behaviors:OrientationBehavior.SnappedStyle>
        </ContentControl>
    </Grid>
</Page>